package com.tencent.qf.team.controller;

import com.alibaba.fastjson.JSON;
import com.tencent.qf.common.pojo.HttpResult;
import com.tencent.qf.team.dto.request.CommdityCouponsCalculatePriceInfoList;
import com.tencent.qf.team.dto.request.CommdityCouponsValidUniqueIdList;
import com.tencent.qf.team.dto.response.CommdityCouponsCalculatePriceInfoResponse;
import com.tencent.qf.team.dto.response.CommdityCouponsValidUniqueIdResponse;
import com.tencent.qf.team.service.CommdityCouponsService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class CommdityCouponsController {

    @Autowired
    private CommdityCouponsService commdityCouponsService;

    @PostMapping("/api/team/commdityCoupons/validUniqueIdList")
    @ApiOperation("获取可领取券的商品")
    public HttpResult<List<CommdityCouponsValidUniqueIdResponse>> validUniqueIdList(
            @RequestBody CommdityCouponsValidUniqueIdList request) {
        log.info("获取可领取券的商品，入参：{}", JSON.toJSONString(request));
        List<CommdityCouponsValidUniqueIdResponse> data = commdityCouponsService.validUniqueIdList(request);
        HttpResult<List<CommdityCouponsValidUniqueIdResponse>> result = HttpResult.success(data);
        log.info("获取可领取券的商品，出参：{}", JSON.toJSONString(result));
        return result;
    }

    @PostMapping("/api/team/commdityCoupons/calculatePriceInfo")
    @ApiOperation("计算券后价格，并返回券详情")
    public HttpResult<CommdityCouponsCalculatePriceInfoResponse> calculatePriceInfo(
            @RequestBody CommdityCouponsCalculatePriceInfoList request) {
        log.info("计算券后价格，并返回券详情，入参：{}", JSON.toJSONString(request));
        CommdityCouponsCalculatePriceInfoResponse data = commdityCouponsService.calculatePriceInfo(request);
        HttpResult<CommdityCouponsCalculatePriceInfoResponse> result = HttpResult.success(data);
        log.info("计算券后价格，并返回券详情，出参：{}", JSON.toJSONString(result));
        return result;
    }
}
